#include "geno.hpp"
#include <boost/assign/std/vector.hpp> // for 'operator+=()'
#include <boost/assign/list_of.hpp>
using namespace boost::assign;

void write_affy6_single()
{
  int discard_lines = 976;
  int discard_cols = 0;
  int sync_interval = 2;
  string genofile = "birdseed-v2.calls.trunc.txt";
  string genotablefile = "hapmap_cpp_test_geno_table.csv";
  vector<int> idlink_ids;
  for(int i=0; i<909; i++)
    idlink_ids.push_back(i);
  map<string, int> annodict;
  annodict["SNP_A-2254440"] = 824339;
  annodict["SNP_A-1780413"] = 585745;
  write_geno_table_affy6_to_file(discard_lines, discard_cols, sync_interval, genofile, genotablefile, idlink_ids, annodict);
}

void write_illumina_single()
{
  int discard_lines=10;
  int sync_interval=2;
  string alleletype("forward");
  string genofile = "Human610-Quadv1_CEU_Genotype_Report.trunc.txt";
  string genotablefile = "ceu_cpp_test_geno_table.csv";
  vector<int > idlink_ids;
  idlink_ids += 2199, 2200, 2201, 2202, 2203, 2204, 2205, 2206, 2207, 2208, 2209, 2210, 2211, 2212, 2213, 2214, 2215, 2216, 2217, 2218, 2219, 2220, 2221, 2222, 2223, 2224, 2225, 2226, 2227, 2228, 2229, 2230, 2231, 2232, 2233, 2234, 2235, 2236, 2237, 2238, 2239, 2240, 2241, 2242, 2243, 2244, 2245, 2246, 2247, 2248, 2249, 2250, 2251, 2252, 2253, 2254, 2255, 2256, 2257, 2258, 2259, 2260, 2261, 2262, 2263, 2264, 2265, 2266, 2267, 2268, 2269, 2270, 2271;

  map<string, map<string, string> > annodict_illumina;
  map<string, string> rs955012_illumina_dict = map_list_of("id", "128531") ("allelea_forward", "A") ("alleleb_forward", "G") ("allelea_top", "A") ("alleleb_top","G");
  //map<string, string> rs4650275_illumina_dict = map_list_of("id", "15067") ("allelea_forward", "T") ("alleleb_forward", "C") ("allelea_top", "A") ("alleleb_top","G");
  // Introduce error in rs465027 for debugging purposes.
  map<string, string> rs4650275_illumina_dict = map_list_of("id", "15067") ("allelea_forward", "T") ("alleleb_forward", "T") ("allelea_top", "A") ("alleleb_top","G");
  map<string, string> rs7552097_illumina_dict = map_list_of("id", "20656") ("allelea_forward", "A") ("alleleb_forward", "G") ("allelea_top", "A") ("alleleb_top", "G");
  map<string, string> rs798075_illumina_dict = map_list_of("id", "7238") ("allelea_forward", "A") ("alleleb_forward", "G") ("allelea_top", "A") ("alleleb_top", "");
  map<string, string> rs943918_illumina_dict = map_list_of("id", "3136") ("allelea_forward", "T") ("alleleb_forward", "C") ("allelea_top", "A") ("alleleb_top", "G");

  annodict_illumina["rs955012"] = rs955012_illumina_dict;
  annodict_illumina["rs4650275"] = rs4650275_illumina_dict;
  annodict_illumina["rs7552097"] = rs7552097_illumina_dict;
  annodict_illumina["rs798075"] = rs798075_illumina_dict;
  annodict_illumina["rs943918"] = rs943918_illumina_dict;

  write_geno_table_illumina_to_file(discard_lines, sync_interval, genofile, genotablefile, idlink_ids, annodict_illumina, alleletype);
}

void write_affy6_shard()
{
  string tmpdir("test_affy6");
  int discard_lines = 976;
  int sync_interval = 2;
  string genofile = "birdseed-v2.calls.trunc.txt";
  vector<int> idlink_ids;
  for(int i=0; i<909; i++)
    idlink_ids.push_back(i);
  map<string, int> annodict;
  annodict["SNP_A-2254440"] = 824339;
  annodict["SNP_A-1780413"] = 585745;
  write_geno_tables_affy6_to_file(tmpdir, discard_lines, sync_interval, genofile, idlink_ids, annodict);
}

void write_illumina_shard()
{
  string tmpdir = "test_illumina";
  int discard_lines=10;
  int sync_interval=2;
  string alleletype("forward");
  string genofile = "Human610-Quadv1_CEU_Genotype_Report.trunc.txt";
  vector<int > idlink_ids;
  idlink_ids += 2199, 2200, 2201, 2202, 2203, 2204, 2205, 2206, 2207, 2208, 2209, 2210, 2211, 2212, 2213, 2214, 2215, 2216, 2217, 2218, 2219, 2220, 2221, 2222, 2223, 2224, 2225, 2226, 2227, 2228, 2229, 2230, 2231, 2232, 2233, 2234, 2235, 2236, 2237, 2238, 2239, 2240, 2241, 2242, 2243, 2244, 2245, 2246, 2247, 2248, 2249, 2250, 2251, 2252, 2253, 2254, 2255, 2256, 2257, 2258, 2259, 2260, 2261, 2262, 2263, 2264, 2265, 2266, 2267, 2268, 2269, 2270, 2271;

  map<string, map<string, string> > annodict_illumina;
  map<string, string> rs955012_illumina_dict = map_list_of("id", "128531") ("allelea_forward", "A") ("alleleb_forward", "G") ("allelea_top", "A") ("alleleb_top","G");
  //map<string, string> rs4650275_illumina_dict = map_list_of("id", "15067") ("allelea_forward", "T") ("alleleb_forward", "C") ("allelea_top", "A") ("alleleb_top","G");
  // Introduce error in rs465027 for debugging purposes.
  map<string, string> rs4650275_illumina_dict = map_list_of("id", "15067") ("allelea_forward", "T") ("alleleb_forward", "T") ("allelea_top", "A") ("alleleb_top","G");
  map<string, string> rs7552097_illumina_dict = map_list_of("id", "20656") ("allelea_forward", "A") ("alleleb_forward", "G") ("allelea_top", "A") ("alleleb_top", "G");
  map<string, string> rs798075_illumina_dict = map_list_of("id", "7238") ("allelea_forward", "A") ("alleleb_forward", "G") ("allelea_top", "A") ("alleleb_top", "");
  map<string, string> rs943918_illumina_dict = map_list_of("id", "3136") ("allelea_forward", "T") ("alleleb_forward", "C") ("allelea_top", "A") ("alleleb_top", "G");

  annodict_illumina["rs955012"] = rs955012_illumina_dict;
  annodict_illumina["rs4650275"] = rs4650275_illumina_dict;
  annodict_illumina["rs7552097"] = rs7552097_illumina_dict;
  annodict_illumina["rs798075"] = rs798075_illumina_dict;
  annodict_illumina["rs943918"] = rs943918_illumina_dict;

  write_geno_tables_illumina_to_file(tmpdir, discard_lines, sync_interval, genofile, idlink_ids, annodict_illumina, alleletype);
}

int main()
{
  write_affy6_single();
  write_illumina_single();
  write_affy6_shard();
  write_illumina_shard();
}
